package org.chz.system;

import javafx.util.Pair;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
@NoArgsConstructor
public class CandidateResult implements Comparable, Serializable{

    private String word;
    private int frequency;
    private int dist;

    public CandidateResult(Pair<String, Integer> pair, int dist) {
        this.word = pair.getKey();
        this.frequency = pair.getValue();
        this.dist = dist;
    }

    @Override
    public String toString() {
        return word;
    }

    /**
     * 返回优先级高的
     * @param obj the object to be compared.
     * @return
     */
    @Override
    public int compareTo(Object obj) {
        CandidateResult rhs = (CandidateResult) obj;

        /* 优先级高返回正数 */
        if (rhs.dist < dist || (dist == rhs.dist && rhs.frequency > frequency)) {
            return 1;
        }

        if (rhs.dist == dist && rhs.frequency == frequency) {
            return 0;
        }

        return -1;
    }
}
